package file;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.CharBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 内存映射文件
 */
public class MappedFileDemo {
    public static void main(String[] args) throws IOException {
        String file = "/Users/guopanbo/Documents/study/java/file/test.txt";
        FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
        MappedByteBuffer mbf = channel.map(FileChannel.MapMode.READ_WRITE, 0, channel.size());
        System.out.println(mbf.get());
        System.out.println(mbf.get());

        mbf.put((byte) 'X').put((byte) 'Y');
        channel.close();
    }
}
